/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.home.dao;

import com.home.common.utils.HibernateUtil;
import com.home.mapping.Account;
import com.home.mapping.Team;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author pnduy
 */
public class TeamDao extends BaseDao{
    
    /**
     * 
     * @param vetnureId
     * @return 
     */
    public List<Team> findTeamsAndAgentsByVenture(Integer ventureId) {
        List<Team> list = new ArrayList<Team>();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Query query = session.createSQLQuery("SELECT * FROM team WHERE team.fk_venture =:ventureId").addEntity(Team.class).setParameter("ventureId", ventureId);
            list = query.list();    
            for (Team t : list) {
                Hibernate.initialize(t.getAgents());
            }         
            
        } catch (Exception e) {
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
        return list;
    }
}
